import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo06 {
    public static void main(String[] args) {
        Set<Person> persons = new TreeSet<>();
        persons.add(new Person("老王", 12));
        persons.add(new Person("老李", 13));
        persons.add(new Person("老李", 10));
        System.out.println(persons.size());//1

        for (Person person : persons) {
            System.out.println(person.getAge());
        }

    }
}

class Person implements Comparable {
    private String name;
    private Integer age;

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public int compareTo(Object o) {
        return this.age - ((Person) o).age;
    }
}
